#ifndef CLIENTCONNECTION_H
#define CLIENTCONNECTION_H

#include <QObject>
#include <QString>
#include <QTcpSocket>
#include <QDataStream>
#include <QByteArray>
#include "Delimetrs.h"

class ClientConnection : public QObject
{
    Q_OBJECT
public:
    explicit ClientConnection(QObject *parent = 0);
    ~ClientConnection();
    //sends message to Host
    void sendMessage(QString message);
    //connects to Host
    void connectToSocket(QString _ip, int _port);
    //disconnects from Host
    void disconnectFromSocket();
    bool connected();

signals:
    //signal for ClientMessagaManager
    //  signals if received a massega of
    //  complite type with delimetrs::eom in the end
    //  EXAMPLE: "asdasda\n\r"
    void signalReceived(QString str);
    //signals to upper classes about connection: success, disconnect, error
    void signalConnectionSuccessfull();
    void signalDisconnectedFromSocket();
    void signalConnectionError(QAbstractSocket::SocketError err);

public slots:
    //catcher of SIGNAL(readyRead())
    //  new bytes are pushed into buffer
    //  if buffer contains complite message emits signalReceived(QString)
    void slotRecieve();
    //slots receivers of QTcpSocket signals about connections
    void slotConnectionSuccessfull();
    void slotConnectionError(QAbstractSocket::SocketError err);
    void slotDisconnectedFromSocket();

private:
    QTcpSocket *m_tcpSocket;
    QString buffer; //buffer for containing not complete messages

};

#endif // CLIENTCONNECTION_H
